// 服务类型枚举
export const ServiceType = {
  DATASET: 'dataset',
  MEDICAL_SCENE: 'medical_scene',
  IMAGE: 'image',
  DEFAULT: 'default',
  RESULTS: 'results',
};
// 医学场景类型枚举
export const MedicalSceneType = {
  // 示例医学场景类型，根据实际场景添加
  GENERAL: 'general',
  PNEUMONIA: 'pneumonia'
};

// 医学场景到服务的映射配置
export const medicalSceneServiceMapping = {
  [MedicalSceneType.GENERAL]: process.env.NEXT_PUBLIC_MEDICAL_SCENE_SERVICE_URL,
  [MedicalSceneType.PNEUMONIA]: process.env.NEXT_PUBLIC_MEDICAL_SCENE_SERVICE_PNEUMONIA_URL
};

// 根据医学场景获取服务URL
export const getMedicalSceneServiceUrl = (sceneType = MedicalSceneType.GENERAL) => {
  return medicalSceneServiceMapping[sceneType] ||
    process.env.NEXT_PUBLIC_MEDICAL_SCENE_SERVICE_URL ||
    process.env.NEXT_PUBLIC_API_BASE_URL;
};

// 服务路由配置
export const serviceConfig = {
  [ServiceType.DATASET]: {
    baseUrl: process.env.NEXT_PUBLIC_DATASET_SERVICE_URL || process.env.NEXT_PUBLIC_API_BASE_URL,
    timeout: 30000
  },
  [ServiceType.MEDICAL_SCENE]: {
    baseUrl: process.env.NEXT_PUBLIC_MEDICAL_SCENE_SERVICE_URL || process.env.NEXT_PUBLIC_API_BASE_URL,
    timeout: 60000
  },
  [ServiceType.IMAGE]: {
    baseUrl: process.env.NEXT_PUBLIC_IMAGE_SERVICE_URL || process.env.NEXT_PUBLIC_API_BASE_URL,
    timeout: 15000
  },
  [ServiceType.DEFAULT]: {
    baseUrl: process.env.NEXT_PUBLIC_API_BASE_URL,
    timeout: 30000
  },
  [ServiceType.RESULTS]: {
    baseUrl: process.env.NEXT_PUBLIC_RESULTS_URL || process.env.NEXT_PUBLIC_API_BASE_URL,
    // timeout: 60000 // 分割时间还是太长，先不要设置超时
  }
};

// 获取服务配置
export const getServiceConfig = (serviceType = ServiceType.DEFAULT) => {
  return serviceConfig[serviceType] || serviceConfig[ServiceType.DEFAULT];
};

// 创建服务实例（可选，用于更细粒度的控制）
export const createServiceInstance = (serviceType = ServiceType.DEFAULT) => {
  const config = getServiceConfig(serviceType);
  const axios = require('axios');

  return axios.create({
    baseURL: config.baseUrl,
    timeout: config.timeout,
    headers: {
      'Content-Type': 'application/json'
    }
  });
};